from datetime import datetime

import pandas as pd

from data.market_data_fetcher import MarketDataFetcher
from infrastructure.model.stock_kline import StockKline
from strategy.selection.ma_strategy import MAStrategy


# Test when symbols is None and start_date is None
def test_update_market_data_all_symbols_all_data():
    fetcher = MarketDataFetcher()
    fetcher.update_stock_data()


def test_sync_realtime_market_data():
    fetcher = MarketDataFetcher()
    fetcher.sync_realtime_market_data()


def test_select():
    strategy = MAStrategy()
    results = strategy.get_strategy_results()
    print(results)  # 显示符合条件的股票信息


def test_model_save():
    # 1. 基本保存
    df = pd.DataFrame({
        'ts_code': ['000001.SZ'],
        'trade_date': [datetime.now().astimezone().date().strftime('%Y-%m-%d')],
        'open': [10.0],
        'close': [11.0]
    })
    StockKline.save(df, index_elements=['ts_code', 'trade_date'])


def test_model_load():
    # 2. 基本加载
    df = StockKline.get_stock_data('688235')
    print(df)


def test_get_last_trade_date():
    df = StockKline.get_latest_date('688235')
    print(df)


def test_get_all():
    df = StockKline.find_all()
    print(df)
